package com.cb2.algorithm.leetcode;

/**
 * @author c2b
 * @since 2025/4/1 11:19
 */
public class LC2140SolvingQuestionsWithBrainpower_M {
    static class Solution {
        public long mostPoints(int[][] questions) {
            int n = questions.length;
            long[] dp = new long[n + 1];
            for (int i = n - 1; i >= 0; i--) {
                int skip = questions[i][0];
                int gain = questions[i][1];
                dp[i] = Math.max(dp[i + 1], dp[Math.min(n, i + skip + 1)] + gain);
            }
            return dp[0];
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.mostPoints(new int[][]{{3, 2}, {4, 3}, {4, 4}, {2, 5}}));
        System.out.println(solution.mostPoints(new int[][]{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}}));
    }
}
